new Vue({
    el: ".container",
    data: {
        user: {
            username: "",
            password: ""
        },
        checkCode: "",
        remember: false,
        codeImg: "/code.jpg"
    },
    methods: {
        toLogin: function () {
            if (this.checkCode != "" && this.user.username != "" && this.user.password != "") {
                axios({
                    method: "post",
                    url: `/user/login/${this.checkCode}`,
                    data: this.user
                }).then(res => {
                    if (res.data.flag) {
                        if (this.remember) {
                            //7天免密登录
                            $.cookie("userId", res.data.data.id, {path: "/", expires: 7});
                        }
                        //存入localStorage
                        localStorage.setItem("loginUser", JSON.stringify(res.data.data));
                        location.href = "/home.html";
                    } else {
                        this.codeImg = this.codeImg + "?" + new Date();
                        layer.msg(res.data.message);
                    }
                });
            }
        },
        code: function () {
            this.codeImg = this.codeImg + "?" + new Date();
        },
        toWxLogin: function () {
            location.href = "/wx/toWxLogin";
        }
    }
})